Spatial Pattern Finding

Global Morans'I

1.Entry Rate

Global Morans'I = 0.146

image.png

image.png

2.HHI

Global Morans'I = 0.296

image.png

image.png

3.Asset

Global Morans'I = 0.025

image.png

image.png

LISA

1. Entry Rate

entry_rate_lisa.png

entry_rate_lisa_sig.png

2. HHI

hh_lisa.png

hh_lisa_sig.png

3. Asset

asset_lisa.png

asset_lisa_sig.png

From the LISA, we can ascertain that there was statistically significant low clustering in England

High entry rate seems to locate on the boundaries of England.

The LISA Cluser Map shows how the attribute entry rate clusters. The red color shows tracts where high rate cluster with high rates, and blue shows where low rates cluster with low rates. There is even a mix of high-low, for example the pink color. So, there is a cluster of high entry rate in the southwest commute area and clusters of lower ownership in the north.

GWR

In (1)

  1. classic

  2. spatial lag

  3. spatial error

In (2)

  1. classic

  2. spatial lag

  3. spatial error

Reproducible Analysis

# read geojson data7

# df_mg.to_csv(PATH + "/HHI_EnR_ttwa_England_for_R.csv")

import geopandas as gpd
import fiona

import sys
PATH = sys.path[0]

# export the geojson
gdf = gpd.read_file(PATH + "/Dataset/Spatial/HHI_EnR_ttwa_England_for_R.geojson")

3 figures will be needed

1998 2008 2018
Entry Rate fig1_a fig1_b fig1_c
HHI fig2_a fig2_b fig2_c
Performance fig3_a fig3_b fig3_c

raw_data contains ttwa, year, entry_rate, hh, assets

In [ ]:
# environment prepare
library(tidyverse)
library(data.table)
library(sp)
library(sf)
library(table1)
library(tm)
library(spatstat)
library(here)
library(sp)
library(rgeos)
# library(maptools)
library(tmap)
library(sf)
library(geojson)
library(geojsonio)
library(tmaptools)
library(RColorBrewer)
library(spdep) 
library(lubridate)
In [512]:
# read data in R
raw_data = read.csv(here::here("Dataset","df_hh_EnR_ttwaName_asset_not_drop.csv"))

# you can have a overview of this dataset
print("The number of rows is: ")
nrow(raw_data)
print("The number of columns is: ")
ncol(raw_data)
print("70 of all varriables are:")
head(names(raw_data),n = 70)
[1] "The number of rows is: "
3089
[1] "The number of columns is: "
9
[1] "70 of all varriables are:"
  1. 'X'
  2. 'ttwa'
  3. 'ttwa_code'
  4. 'year'
  5. 'firms'
  6. 'total_firms'
  7. 'entry_rate'
  8. 'hh'
  9. 'average_assets'
In [513]:
# import spatial dataset

eng_ttwa = st_read(here::here("Dataset","Spatial","eng_ttwa_boundary.geojson"))
Reading layer `eng_ttwa_boundary' from data source `/Users/fangzeqiang/Github/Master-Dissertation/Dataset/Spatial/eng_ttwa_boundary.geojson' using driver `GeoJSON'
Simple feature collection with 149 features and 5 fields
geometry type:  MULTIPOLYGON
dimension:      XY
bbox:           xmin: -6.418524 ymin: 49.86474 xmax: 1.762942 ymax: 55.54107
CRS:            4326
In [514]:
# plot the map
plot(st_geometry(eng_ttwa))
In [515]:
dfm = merge(raw_data,eng_ttwa,by.x="ttwa_code",by.y="TTWA11CD",all = TRUE)
In [516]:
# calculate the density of tech firms in ttwa

# df merged & density is calculated

#dfm_den_cal = dfm %>%
#    mutate(area=st_area(.))%>%
#    mutate(density = firms*1000*1000/area)

#head(dfm_den_cal)
In [517]:
tmap_mode("plot")
tmap mode set to plotting

Data Prepare

In [548]:
# select year
df_1998 = raw_data %>% filter(year==1998)
df_2008 = raw_data %>% filter(year==2008)
df_2018 = raw_data %>% filter(year==2018)
df_2017_2018 = raw_data %>% filter(year==2017 | year==2018)

# merge
dfm_1998 = merge(eng_ttwa,df_1998,by.x="TTWA11CD",by.y="ttwa_code",all.x = TRUE)
dfm_2008 = merge(eng_ttwa,df_2008,by.x="TTWA11CD",by.y="ttwa_code",all.x = TRUE)
dfm_2018 = merge(eng_ttwa,df_2018,by.x="TTWA11CD",by.y="ttwa_code",all.x = TRUE)
dfm_2017_2018 = merge(eng_ttwa,df_2017_2018,by.x="TTWA11CD",by.y="ttwa_code",all.x = TRUE)
dfm_all = merge(eng_ttwa,raw_data,by.x="TTWA11CD",by.y="ttwa_code",all.x = TRUE)

# n/a -> 0
dfm_1998 = dfm_1998 %>% replace_na(list(entry_rate=0,hh=0,average_assets=0))
dfm_2008 = dfm_2008 %>% replace_na(list(entry_rate=0,hh=0,average_assets=0))
dfm_2018 = dfm_2018 %>% replace_na(list(entry_rate=0,hh=0,average_assets=0))
dfm_2017_2018 = dfm_2017_2018 %>% replace_na(list(entry_rate=0,hh=0,average_assets=0))
dfm_all = dfm_all %>% replace_na(list(entry_rate=0,hh=0,average_assets=0))
In [519]:
cus_break = c(0,0.02,0.04,0.06,0.08,0.1,0.12,0.14,0.16,0.18,0.2,0.22,0.24,0.26,0.28,0.3,0.32,0.34,0.36,0.38,0.4)

df = dfm_2018

tm_shape(df) +
  tm_polygons(col = "entry_rate",
              legend.hist = TRUE,
             title = "xx",
             breaks = cus_break) +
  tm_layout(legend.outside = TRUE) +
  tm_borders()

Entry Rate

build the break

In [520]:
summary(dfm_all$entry_rate)
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
0.002457 0.018182 0.035029 0.048236 0.072000 0.312686 
In [521]:
summary(dfm_1998$entry_rate)
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
0.000000 0.007463 0.010000 0.010611 0.013026 0.029851 
In [522]:
summary(dfm_2008$entry_rate)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
0.00000 0.02289 0.02941 0.02911 0.03409 0.07692 
In [523]:
summary(dfm_2018$entry_rate)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
0.04667 0.12153 0.13924 0.14328 0.16108 0.31269 
In [549]:
# cus_break = c(0,0.01,0.02,0.03,0.08,0.1,0.12,0.14,0.16,0.18,0.2,0.22,0.24,0.26,0.28,0.3,0.32,0.34,0.36,0.38,0.4)
# cus_break = c(0,0.04,0.08,0.12,0.16,0.2,0.24,0.28,0.32,0.36,0.4)
# cus_break = c(0,0.01,0.04,0.16,0.32,0.4)
# cus_break = c(0,0.001,0.005,0.01,0.03,0.05,0.10,0.15,0.2,0.4)
# cus_break = c(0,0.002457,0.018182,0.035029,0.048236,0.12153,0.14328,0.16108,0.32)

cus_break = c(0.00,0.007,0.01,0.013,0.03,0.035,0.077,0.12153,0.14,0.16,0.32)
# library(viridis)
In [525]:
# adjust with the colour
# tmaptools::palette_explorer()
In [600]:
dfm %>% info
Error in info(.): could not find function "info"
Traceback:

1. dfm %>% info
In [598]:
# plot the figure: The distribution of the density of the London charge points in 2019
# Title: The distribution of the entry rate of the England tech clusters(ttwa) from 1998 to 2018
df = dfm_1998
map_var = "entry_rate"
spatial_var = "ttwa"
legend_name = "Entry Rate (1998)"
title_name = "The Distribution of the Entry Rate of the England Tech Clusters(ttwa) in 1998"

enR_1998_map = tm_shape( df )+ 
        tm_compass( north = 0,
              type = "4star",
#               text.size = 0.8,
#               size = 5.5,
              show.labels = TRUE,
              cardinal.directions = c("N", "E", "S", "W"),
              lwd = 1,
              position = c("left","center"),
              bg.color = NA,
              bg.alpha = NA,
              just = NA)+ 
        tm_scale_bar(position=c("left", "center"),
#                      text.size = 1.5
                     breaks =c(50,100,150)
                    )+ 
#         tm_credits("Visualization by Zeqiang Fang",size=.6,position = c(.73, .0085),fontface = "bold")+ 
        tm_fill(col = map_var,
#               style="jenks",
              palette = "BuPu", n = 12,
#               pal = viridis(10, direction = -1),
              breaks = cus_break, 
#               popup.vars=c(spatial_var, map_var),
              title=legend_name,
#               title.size = 1.5,
              legend.hist = TRUE,
              legend.hist.position = c("left", "center")
              )+ 
        tm_layout(main.title = "",main.title.size = .85,
                 frame=FALSE,
                 legend.outside =TRUE,
                 legend.hist.width = 1.2,
                 legend.hist.height = .25 )+
        tm_borders(col = "#D2D2D2", lwd = .5, lty = "solid", alpha = NA)


enR_1998_map
# tmap_arrange(enR_1998_map,tm_tmp1)
# enR_1998_map %>% tmap_save(here("Img","enR_1998.png"),dpi=300)
In [579]:
head(dfm)
A data.frame: 6 × 14
ttwa_codeXttwayearfirmstotal_firmsentry_ratehhaverage_assetsOBJECTIDTTWA11NMShape__AreaShape__Lengthgeometry
<fct><int><fct><int><int><int><dbl><dbl><dbl><int><fct><dbl><dbl><MULTIPOLYGON [°]>
1E300000040Barnsley1998107490.0133511350.12000000 19405.251Barnsley342499168129308.3MULTIPOLYGON (((-1.44681 53...
2E300000041Barnsley1999 67490.0080106810.33333333759500.501Barnsley342499168129308.3MULTIPOLYGON (((-1.44681 53...
3E300000042Barnsley2000 87490.0106809080.15625000286162.331Barnsley342499168129308.3MULTIPOLYGON (((-1.44681 53...
4E300000043Barnsley2001 87490.0106809080.12500000129527.431Barnsley342499168129308.3MULTIPOLYGON (((-1.44681 53...
5E300000044Barnsley2002117490.0146862480.09090909 56740.401Barnsley342499168129308.3MULTIPOLYGON (((-1.44681 53...
6E300000045Barnsley2003207490.0267022700.13000000 78448.901Barnsley342499168129308.3MULTIPOLYGON (((-1.44681 53...
In [551]:
# plot the figure: The distribution of the density of the London charge points in 2019
# Title: The distribution of the entry rate of the England tech clusters(ttwa) from 1998 to 2018
df = dfm_2008
map_var = "entry_rate"
spatial_var = "ttwa"
legend_name = "Entry Rate (2008)"
title_name = "The Distribution of the Entry Rate of the England Tech Clusters(ttwa) in 2008"

enR_2008_map = tm_shape( df )+ 
        tm_compass( north = 0,
              type = "4star",
#               text.size = 0.8,
#               size = 5.5,
              show.labels = TRUE,
              cardinal.directions = c("N", "E", "S", "W"),
              lwd = 1,
              position = c("left","center"),
              bg.color = NA,
              bg.alpha = NA,
              just = NA)+ 
        tm_scale_bar(position=c("left", "center"),
#                      text.size = 1.5
                    )+ 
#         tm_credits("Visualization by Zeqiang Fang",size=.6,position = c(.73, .0085),fontface = "bold")+ 
        tm_fill(col = map_var,
#               style="jenks",
              palette = "BuPu", n = 7,
#               pal = viridis(10, direction = -1),
              breaks = cus_break, 
#               popup.vars=c(spatial_var, map_var),
              title=legend_name,
#               title.size = 1.5,
              legend.hist = TRUE,
              legend.hist.position = c("left", "center")
              )+ 
        tm_layout(main.title = "",main.title.size = .85,
                 frame=FALSE,
                 legend.outside =TRUE,
                 legend.hist.width = 1.2,
                 legend.hist.height = .25 )+
        tm_borders(col = "#D2D2D2", lwd = .5, lty = "solid", alpha = NA)

enR_2008_map
# enR_1998_map %>% tmap_save(here("Img","enR_1998.png"),dpi=300)
In [552]:
# plot the figure: The distribution of the density of the London charge points in 2019
# Title: The distribution of the entry rate of the England tech clusters(ttwa) from 1998 to 2018
df = dfm_2018
map_var = "entry_rate"
spatial_var = "ttwa"
legend_name = "Entry Rate (2018)"
title_name = "The Distribution of the Entry Rate of the England Tech Clusters(ttwa) in 2018"

enR_2018_map = tm_shape( df )+ 
        tm_compass( north = 0,
              type = "4star",
#               text.size = 0.8,
#               size = 5.5,
              show.labels = TRUE,
              cardinal.directions = c("N", "E", "S", "W"),
              lwd = 1,
              position = c("left","center"),
              bg.color = NA,
              bg.alpha = NA,
              just = NA)+ 
        tm_scale_bar(position=c("left", "center"),
#                      text.size = 1.5
                    )+ 
        tm_credits("Visualization by Zeqiang Fang",size=.6,position = c(.65, .0085),fontface = "bold")+ 
        tm_fill(col = map_var,
#               style="jenks",
              palette = "BuPu", n = 7,
#               pal = viridis(10, direction = -1),
              breaks = cus_break, 
#               popup.vars=c(spatial_var, map_var),
              title=legend_name,
#               title.size = 1.5,
              legend.hist = TRUE,
              legend.hist.position = c("left", "center")
              )+ 
        tm_layout(main.title = "",main.title.size = .85,
                 frame=FALSE,
                 legend.outside =TRUE,
                 legend.hist.width = 1.2,
                 legend.hist.height = .25 )+
        tm_borders(col = "#D2D2D2", lwd = .5, lty = "solid", alpha = NA)

enR_2018_map
# enR_1998_map %>% tmap_save(here("Img","enR_1998.png"),dpi=300)
In [553]:
enR_tmap = tmap_arrange(enR_1998_map,enR_2008_map,enR_2018_map,ncol = 1)

enR_tmap

# enR_tmap %>% tmap_save(.,here("Img","map_entry_rate_1998_to_2018.png"),dpi = 300)
In [554]:
enR_tmap %>% tmap_save(.,here("Img","map_entry_rate_1998_to_2018.png"),dpi = 300)
Map saved to /Users/fangzeqiang/Github/Master-Dissertation/Img/map_entry_rate_1998_to_2018.png

Resolution: 2100 by 2100 pixels

Size: 7 by 7 inches (300 dpi)

In [555]:
# animation 
library(viridis)
library(gifski)
enR_animation <- tm_shape(dfm_all) +
  tm_polygons(
    col = "entry_rate",
    style = "cont",
    pal = "BuGn"
    ) +
  tm_facets(along = "year") +
  tm_layout(legend.position = c("left", "bottom"))
tmap_animation(
  enR_animation, filename = "enR.gif",
  delay = 50, width = 2400, height = 1200
  )
Creating frames
================================================================================
Creating animation
Animation saved to /Users/fangzeqiang/Github/Master-Dissertation/enR.gif 
In [531]:
nrow(dfm_all)
3089

HHI

In [532]:
summary(dfm_all$hh)
# cus_break = c(0.002457,0.018182,0.035029,0.048236,0.072000,0.312686 )
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
0.03968 0.07292 0.10000 0.15342 0.15625 1.00000 
In [533]:
cus_break = c(0,0.03968,0.07292,0.10000,0.15342,0.15625,1.00000)
In [534]:
# plot the figure: The distribution of the density of the London charge points in 2019
# Title: The distribution of the entry rate of the England tech clusters(ttwa) from 1998 to 2018

df = dfm_1998
map_var = "hh"
spatial_var = "ttwa"
legend_name = " Herfindahl-Hirschman Index (1998)"
title_name = "The Distribution of the  Herfindahl-Hirschman Index of the England Tech Clusters(ttwa) in 1998"

hhi_1998_map = tm_shape( df )+ 
        tm_compass( north = 0,
              type = "4star",
#               text.size = 0.8,
#               size = 5.5,
              show.labels = TRUE,
              cardinal.directions = c("N", "E", "S", "W"),
              lwd = 1,
              position = c("left","center"),
              bg.color = NA,
              bg.alpha = NA,
              just = NA)+ 
        tm_scale_bar(position=c("left", "center"),
#                      text.size = 1.5
                    )+ 
#         tm_credits("Visualization by Zeqiang Fang",size=.6,position = c(.73, .0085),fontface = "bold")+ 
        tm_fill(col = map_var,
#               style="jenks",
              palette = "BuGn", n = 7,
#               pal = viridis(10, direction = -1),
              breaks = cus_break, 
#               popup.vars=c(spatial_var, map_var),
              title=legend_name,
#               title.size = 1.5,
              legend.hist = TRUE,
              legend.hist.position = c("left", "center")
              )+ 
        tm_layout(main.title = "",
                  main.title.size = .85,
                 frame=FALSE,
                 legend.outside =TRUE,
                 legend.hist.width = .85,
                 legend.hist.height = .25)+
        tm_borders(col = "#D2D2D2", lwd = .5, lty = "solid", alpha = NA)

hhi_1998_map

# enR_1998_map %>% tmap_save(here("Img","enR_1998.png"),dpi=300)
In [535]:
# plot the figure: The distribution of the density of the London charge points in 2019
# Title: The distribution of the entry rate of the England tech clusters(ttwa) from 1998 to 2018

df = dfm_2008
map_var = "hh"
spatial_var = "ttwa"
legend_name = " Herfindahl-Hirschman Index (2008)"
title_name = "The Distribution of the  Herfindahl-Hirschman Index of the England Tech Clusters(ttwa) in 2008"

hhi_2008_map = tm_shape( df )+ 
        tm_compass( north = 0,
              type = "4star",
#               text.size = 0.8,
#               size = 5.5,
              show.labels = TRUE,
              cardinal.directions = c("N", "E", "S", "W"),
              lwd = 1,
              position = c("left","center"),
              bg.color = NA,
              bg.alpha = NA,
              just = NA)+ 
        tm_scale_bar(position=c("left", "center"),
#                      text.size = 1.5
                    )+ 
#         tm_credits("Visualization by Zeqiang Fang",size=.6,position = c(.73, .0085),fontface = "bold")+ 
        tm_fill(col = map_var,
#               style="jenks",
              palette = "BuGn", n = 7,
#               pal = viridis(10, direction = -1),
              breaks = cus_break, 
#               popup.vars=c(spatial_var, map_var),
              title=legend_name,
#               title.size = 1.5,
              legend.hist = TRUE,
              legend.hist.position = c("left", "center")
              )+ 
        tm_layout(main.title = "",
                  main.title.size = .85,
                 frame=FALSE,
                 legend.outside =TRUE,
                 legend.hist.width = .85,
                 legend.hist.height = .25)+
        tm_borders(col = "#D2D2D2", lwd = .5, lty = "solid", alpha = NA)

hhi_2008_map

# enR_1998_map %>% tmap_save(here("Img","enR_1998.png"),dpi=300)
In [536]:
# plot the figure: The distribution of the density of the London charge points in 2019
# Title: The distribution of the entry rate of the England tech clusters(ttwa) from 1998 to 2018

df = dfm_2018
map_var = "hh"
spatial_var = "ttwa"
legend_name = " Herfindahl-Hirschman Index (2018)"
title_name = "The Distribution of the  Herfindahl-Hirschman Index of the England Tech Clusters(ttwa) in 2018"

hhi_2018_map = tm_shape( df )+ 
        tm_compass( north = 0,
              type = "4star",
#               text.size = 0.8,
#               size = 5.5,
              show.labels = TRUE,
              cardinal.directions = c("N", "E", "S", "W"),
              lwd = 1,
              position = c("left","center"),
              bg.color = NA,
              bg.alpha = NA,
              just = NA)+ 
        tm_scale_bar(position=c("left", "center"),
#                      text.size = 1.5
                    )+ 
        tm_credits("Visualization by Zeqiang Fang",size=.6,position = c(.73, .0085),fontface = "bold")+ 
        tm_fill(col = map_var,
#               style="jenks",
              palette = "BuGn", n = 7,
#               pal = viridis(10, direction = -1),
              breaks = cus_break, 
#               popup.vars=c(spatial_var, map_var),
              title=legend_name,
#               title.size = 1.5,
              legend.hist = TRUE,
              legend.hist.position = c("left", "center")
              )+ 
        tm_layout(main.title = "",
                  main.title.size = .85,
                 frame=FALSE,
                 legend.outside =TRUE,
                 legend.hist.width = .85,
                 legend.hist.height = .25)+
        tm_borders(col = "#D2D2D2", lwd = .5, lty = "solid", alpha = NA)

hhi_2018_map

# enR_1998_map %>% tmap_save(here("Img","enR_1998.png"),dpi=300)
In [537]:
hh_tmap = tmap_arrange(hhi_1998_map,hhi_2008_map,hhi_2018_map,ncol=1)

hh_tmap

# enR_tmap %>% tmap_save(.,here("Img","map_entry_rate_1998_to_2018.png"),dpi = 300)
In [545]:
hh_tmap %>% tmap_save(.,here("Img","map_hh_1998_to_2018.png"),dpi = 300)
Map saved to /Users/fangzeqiang/Github/Master-Dissertation/Img/map_hh_1998_to_2018.png

Resolution: 2100 by 2100 pixels

Size: 7 by 7 inches (300 dpi)

Performance

In [538]:
df_1998 = raw_data %>% filter(year==1998)
df_2008 = raw_data %>% filter(year==2008)
df_2018 = raw_data %>% filter(year==2018)
df_2016 = raw_data %>% filter(year==2016)
df_2017 = raw_data %>% filter(year==2017)
df_2017_2018 = raw_data %>% filter(year==2017 | year==2018)

# merge
dfm_1998 = merge(eng_ttwa,df_1998,by.x="TTWA11CD",by.y="ttwa_code",all.x = TRUE)
dfm_2008 = merge(eng_ttwa,df_2008,by.x="TTWA11CD",by.y="ttwa_code",all.x = TRUE)
dfm_2018 = merge(eng_ttwa,df_2018,by.x="TTWA11CD",by.y="ttwa_code",all.x = TRUE)
dfm_2017 = merge(eng_ttwa,df_2017,by.x="TTWA11CD",by.y="ttwa_code",all.x = TRUE)
dfm_2016 = merge(eng_ttwa,df_2016,by.x="TTWA11CD",by.y="ttwa_code",all.x = TRUE)
dfm_all = merge(eng_ttwa,raw_data,by.x="TTWA11CD",by.y="ttwa_code",all.x = TRUE)

build the custom breaks

In [539]:
dfm_all$average_assets %>% summary()
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
      0   36420   74111  126571  149514 8532989 
In [540]:
dfm_1998$average_assets %>% summary()
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
      0   69489  142248  212893  265075 1857840       7 
In [541]:
dfm_2008$average_assets %>% summary()
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
      0   58893   94608  143101  137814 5307552       2 
In [542]:
raw_data %>% 
filter(.,year==2014)%>% 
summary()
       X                       ttwa         ttwa_code        year     
 Min.   :  16   Andover          :  1   E30000004:  1   Min.   :2014  
 1st Qu.: 776   Ashford          :  1   E30000018:  1   1st Qu.:2014  
 Median :1546   Banbury          :  1   E30000029:  1   Median :2014  
 Mean   :1547   Barnsley         :  1   E30000039:  1   Mean   :2014  
 3rd Qu.:2315   Barnstaple       :  1   E30000046:  1   3rd Qu.:2014  
 Max.   :3084   Barrow-in-Furness:  1   E30000051:  1   Max.   :2014  
                (Other)          :143   (Other)  :143                 
     firms          total_firms       entry_rate            hh         
 Min.   :    1.0   Min.   :    54   Min.   :0.01852   Min.   :0.03968  
 1st Qu.:   27.0   1st Qu.:   316   1st Qu.:0.07843   1st Qu.:0.06774  
 Median :   70.0   Median :   777   Median :0.08802   Median :0.08390  
 Mean   :  221.8   Mean   :  2446   Mean   :0.08676   Mean   :0.10569  
 3rd Qu.:  177.0   3rd Qu.:  1876   3rd Qu.:0.09574   3rd Qu.:0.11317  
 Max.   :10387.0   Max.   :113412   Max.   :0.12174   Max.   :1.00000  
                                                                       
 average_assets  
 Min.   :     2  
 1st Qu.: 34886  
 Median : 44074  
 Mean   : 50213  
 3rd Qu.: 56449  
 Max.   :227351  
                 
In [543]:
cus_break = c(0,56900,58518,60194,91560,135434,141180,202891,263037,5307552,8532989,18578409)
In [544]:
# plot the figure: The distribution of the density of the London charge points in 2019
# Title: The distribution of the entry rate of the England tech clusters(ttwa) from 1998 to 2018
df = dfm_2016
map_var = "average_assets"
spatial_var = "ttwa"
legend_name = "Entry Rate (2018)"
title_name = "The Distribution of the Entry Rate of the England Tech Clusters(ttwa) in 2018"

l1 = tm_shape( df )+ 
        tm_compass( north = 0,
              type = "4star",
#               text.size = 0.8,
#               size = 5.5,
              show.labels = TRUE,
              cardinal.directions = c("N", "E", "S", "W"),
              lwd = 1,
              position = c("left","center"),
              bg.color = NA,
              bg.alpha = NA,
              just = NA)+ 
        tm_scale_bar(position=c("left", "center"),
#                      text.size = 1.5
                    )+ 
        tm_credits("Visualization by Zeqiang Fang",size=.6,position = c(.65, .0085),fontface = "bold")+ 
        tm_fill(col = map_var,
#               style="jenks",
              palette = "Blues", n = 7,
#               pal = viridis(10, direction = -1),
#               breaks = cus_break, 
#               popup.vars=c(spatial_var, map_var),
              title=legend_name,
#               title.size = 1.5,
              legend.hist = TRUE,
              legend.hist.position = c("left", "center")
              )+ 
        tm_layout(main.title = "",main.title.size = .85,
                 frame=FALSE,
                 legend.outside =TRUE,
                 legend.hist.width = 1.2,
                 legend.hist.height = .25 )+
        tm_borders(col = "#D2D2D2", lwd = .5, lty = "solid", alpha = NA)
l1

# assets_2018_map
# enR_1998_map %>% tmap_save(here("Img","enR_1998.png"),dpi=300)

Density of Tech Firms in ttwa of England

In [711]:
head(dfm_all)
A sf: 6 × 14
TTWA11CDOBJECTIDTTWA11NMShape__AreaShape__LengthXttwayearfirmstotal_firmsentry_ratehhaverage_assetsgeometry
<fct><int><fct><dbl><dbl><int><fct><int><int><int><dbl><dbl><dbl><MULTIPOLYGON [°]>
1E300000041Barnsley342499168129308.30Barnsley1998107490.0133511350.12000000 19405.25MULTIPOLYGON (((-1.44681 53...
2E300000041Barnsley342499168129308.31Barnsley1999 67490.0080106810.33333333759500.50MULTIPOLYGON (((-1.44681 53...
3E300000041Barnsley342499168129308.32Barnsley2000 87490.0106809080.15625000286162.33MULTIPOLYGON (((-1.44681 53...
4E300000041Barnsley342499168129308.33Barnsley2001 87490.0106809080.12500000129527.43MULTIPOLYGON (((-1.44681 53...
5E300000041Barnsley342499168129308.34Barnsley2002117490.0146862480.09090909 56740.40MULTIPOLYGON (((-1.44681 53...
6E300000041Barnsley342499168129308.35Barnsley2003207490.0267022700.13000000 78448.90MULTIPOLYGON (((-1.44681 53...
In [715]:
dfm3 = dfm_all %>% 
    mutate(area = st_area(geometry))%>%
    mutate(area_km = units::set_units(area,km^2))%>%
    mutate(density = firms / area_km)%>%
    select(TTWA11CD,ttwa,year,entry_rate,hh,average_assets,density,firms,area_km)
In [724]:
# 输出dfm3
dfm3 %>% write_csv(here("Dataset","year_ttwa_enR_hh_den.csv"))
In [649]:
df = dfm1 %>% filter(year==2018)
map_var = "density"
legend_name = " Density(1/km^2)"
title_name = "The Distribution of The Density of the England Tech Clusters(ttwa) in 2018"

den_map = tm_shape( df )+ 
        tm_compass( north = 0,
              type = "4star",
              show.labels = TRUE,
              cardinal.directions = c("N", "E", "S", "W"),
              lwd = 1,
              position = c("left","center"),
              bg.color = NA,
              bg.alpha = NA,
              just = NA)+ 
        tm_scale_bar(position=c("left", "center"),
                    )+ 
        tm_credits("Visualization by Zeqiang Fang",size=.6,position = c(.73, .0085),fontface = "bold")+ 
        tm_fill(col = map_var,
              palette = "BuGn", n = 20,
#               breaks = cus_break, 
              title=legend_name,
              legend.hist = TRUE,
              legend.hist.position = c("left", "center")
              )+ 
        tm_layout(main.title = "",
                  main.title.size = .85,
                 frame=FALSE,
                 legend.outside =TRUE,
                 legend.hist.width = .85,
                 legend.hist.height = .25)+
        tm_borders(col = "#D2D2D2", lwd = .5, lty = "solid", alpha = NA)

den_map

# enR_1998_map %>% tmap_save(here("Img","enR_1998.png"),dpi=300)

Moran's I

set a new coordsw

In [687]:
library(spdep)
In [726]:
df = dfm3%>%
    st_transform(.,27700)
In [727]:
df %>% st_crs()
Coordinate Reference System:
  User input: EPSG:27700 
  wkt:
PROJCS["OSGB 1936 / British National Grid",
    GEOGCS["OSGB 1936",
        DATUM["OSGB_1936",
            SPHEROID["Airy 1830",6377563.396,299.3249646,
                AUTHORITY["EPSG","7001"]],
            TOWGS84[446.448,-125.157,542.06,0.15,0.247,0.842,-20.489],
            AUTHORITY["EPSG","6277"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4277"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",49],
    PARAMETER["central_meridian",-2],
    PARAMETER["scale_factor",0.9996012717],
    PARAMETER["false_easting",400000],
    PARAMETER["false_northing",-100000],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["Easting",EAST],
    AXIS["Northing",NORTH],
    AUTHORITY["EPSG","27700"]]
In [728]:
coordsW = df%>%
   st_centroid()%>%
   st_geometry()
In [733]:
plot(coordsW,axes=TRUE)
In [738]:
df %>% list(1)
  1. A sf: 3089 × 10
    TTWA11CDttwayearentry_ratehhaverage_assetsdensityfirmsarea_kmgeometry
    <fct><fct><int><dbl><dbl><dbl><[1/km^2]><int><[km^2]><MULTIPOLYGON [m]>
    1E30000004Barnsley19980.0133511350.12000000 19405.250.02917664 [1/km^2]10342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    2E30000004Barnsley19990.0080106810.33333333759500.500.01750598 [1/km^2] 6342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    3E30000004Barnsley20000.0106809080.15625000286162.330.02334131 [1/km^2] 8342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    4E30000004Barnsley20010.0106809080.12500000129527.430.02334131 [1/km^2] 8342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    5E30000004Barnsley20020.0146862480.09090909 56740.400.03209430 [1/km^2]11342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    6E30000004Barnsley20030.0267022700.13000000 78448.900.05835327 [1/km^2]20342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    7E30000004Barnsley20040.0226969290.12110727456372.250.04960028 [1/km^2]17342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    8E30000004Barnsley20050.0200267020.09333333 75669.570.04376495 [1/km^2]15342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    9E30000004Barnsley20060.0307076100.09262760127381.530.06710626 [1/km^2]23342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    10E30000004Barnsley20070.0186915890.14285714 13652.420.04084729 [1/km^2]14342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    11E30000004Barnsley20080.0267022700.12500000 64590.740.05835327 [1/km^2]20342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    12E30000004Barnsley20090.0347129510.11538461121352.250.07585925 [1/km^2]26342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    13E30000004Barnsley20100.0333778370.06880000129818.390.07294159 [1/km^2]25342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    14E30000004Barnsley20110.0453938580.06228374199891.710.09920056 [1/km^2]34342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    15E30000004Barnsley20120.0574098800.04056246 69002.700.12545953 [1/km^2]43342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    16E30000004Barnsley20130.0720961280.05281207 46640.060.15755383 [1/km^2]54342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    17E30000004Barnsley20140.1028037380.06392309 31777.400.22466009 [1/km^2]77342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    18E30000004Barnsley20150.1214953270.05566960 22799.150.26550738 [1/km^2]91342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    19E30000004Barnsley20160.0961281710.06211420 26799.150.21007178 [1/km^2]72342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    20E30000004Barnsley20170.1094793060.04788816 30249.000.23924841 [1/km^2]82342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    21E30000004Barnsley20180.1241655540.05214476 4643.000.27134271 [1/km^2]93342.7400 [km^2]MULTIPOLYGON (((436695.4 41...
    22E30000018Bradford19980.0062111800.33884297 29856.560.03196363 [1/km^2]11344.1412 [km^2]MULTIPOLYGON (((403773.1 45...
    23E30000018Bradford19990.0039525690.22448979 73499.670.02034049 [1/km^2] 7344.1412 [km^2]MULTIPOLYGON (((403773.1 45...
    24E30000018Bradford20000.0101637490.11111111140282.600.05230412 [1/km^2]18344.1412 [km^2]MULTIPOLYGON (((403773.1 45...
    25E30000018Bradford20010.0067758330.18055555126293.430.03486941 [1/km^2]12344.1412 [km^2]MULTIPOLYGON (((403773.1 45...
    26E30000018Bradford20020.0129870130.08128544202714.720.06683304 [1/km^2]23344.1412 [km^2]MULTIPOLYGON (((403773.1 45...
    27E30000018Bradford20030.0129870130.08884688113444.110.06683304 [1/km^2]23344.1412 [km^2]MULTIPOLYGON (((403773.1 45...
    28E30000018Bradford20040.0152456240.11934156136027.740.07845617 [1/km^2]27344.1412 [km^2]MULTIPOLYGON (((403773.1 45...
    29E30000018Bradford20050.0152456240.08367627123411.640.07845617 [1/km^2]27344.1412 [km^2]MULTIPOLYGON (((403773.1 45...
    30E30000018Bradford20060.0214568040.12603878 72112.970.11041980 [1/km^2]38344.1412 [km^2]MULTIPOLYGON (((403773.1 45...
    3060E30000293Yeovil20100.0316091950.09090909136991.590.019384341 [1/km^2] 221134.937 [km^2]MULTIPOLYGON (((371733.3 13...
    3061E30000293Yeovil20110.0431034480.06444444 41112.070.026433193 [1/km^2] 301134.937 [km^2]MULTIPOLYGON (((371733.3 13...
    3062E30000293Yeovil20120.0632183910.04338843 65850.880.038768683 [1/km^2] 441134.937 [km^2]MULTIPOLYGON (((371733.3 13...
    3063E30000293Yeovil20130.0603448280.06122449 42219.620.037006470 [1/km^2] 421134.937 [km^2]MULTIPOLYGON (((371733.3 13...
    3064E30000293Yeovil20140.0790229890.05983471 29426.480.048460853 [1/km^2] 551134.937 [km^2]MULTIPOLYGON (((371733.3 13...
    3065E30000293Yeovil20150.0790229890.09619835 21791.920.048460853 [1/km^2] 551134.937 [km^2]MULTIPOLYGON (((371733.3 13...
    3066E30000293Yeovil20160.0948275860.05188246 28276.690.058153024 [1/km^2] 661134.937 [km^2]MULTIPOLYGON (((371733.3 13...
    3067E30000293Yeovil20170.0919540230.07031250 57387.440.056390811 [1/km^2] 641134.937 [km^2]MULTIPOLYGON (((371733.3 13...
    3068E30000293Yeovil20180.1508620690.05451247 0.000.092516174 [1/km^2]1051134.937 [km^2]MULTIPOLYGON (((371733.3 13...
    3069E30000294York 19980.0127569100.15432099193297.770.010082711 [1/km^2] 181785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3070E30000294York 19990.0099220410.15306122348464.300.007842109 [1/km^2] 141785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3071E30000294York 20000.0127569100.09876543304054.360.010082711 [1/km^2] 181785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3072E30000294York 20010.0106307580.09333333114553.580.008402259 [1/km^2] 151785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3073E30000294York 20020.0198440820.08163265419738.780.015684218 [1/km^2] 281785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3074E30000294York 20030.0326009920.07561437240210.920.025766929 [1/km^2] 461785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3075E30000294York 20040.0283486890.07000000210303.560.022406025 [1/km^2] 401785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3076E30000294York 20050.0262225370.08838568222356.150.020725573 [1/km^2] 371785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3077E30000294York 20060.0276399720.08349770156634.830.021845875 [1/km^2] 391785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3078E30000294York 20070.0403968820.11049554112569.330.031928586 [1/km^2] 571785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3079E30000294York 20080.0368532960.08949704269327.670.029127833 [1/km^2] 521785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3080E30000294York 20090.0340184270.05468750164688.440.026887230 [1/km^2] 481785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3081E30000294York 20100.0552799430.07034845184008.300.043691749 [1/km^2] 781785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3082E30000294York 20110.0531537920.08017778140836.210.042011297 [1/km^2] 751785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3083E30000294York 20120.0581148120.05175491110249.960.045932352 [1/km^2] 821785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3084E30000294York 20130.0701630050.06234058164746.100.055454912 [1/km^2] 991785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3085E30000294York 20140.0963855420.05341695227350.990.076180486 [1/km^2]1361785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3086E30000294York 20150.0914245220.07289225 35323.840.072259431 [1/km^2]1291785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3087E30000294York 20160.0836286320.05458202207957.610.066097774 [1/km^2]1181785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3088E30000294York 20170.0892983700.06840514276970.480.070578979 [1/km^2]1261785.234 [km^2]MULTIPOLYGON (((468521 4200...
    3089E30000294York 20180.1105598870.05917160 0.000.087383498 [1/km^2]1561785.234 [km^2]MULTIPOLYGON (((468521 4200...
  2. 1
In [739]:
df = df%>%
    filter(year==2008)
    group_by(TTWA11CD,year) %>%
    summarise(
        density = first(density),
        ttwa = first(ttwa)
    )

tm_shape(df) +
    tm_polygons("density",
        style="jenks",
        palette="PuOr",
        midpoint=NA,
#         popup.vars=c("wardname", "density"),
        title="Blue Plaque Density")
`summarise()` has grouped output by 'TTWA11CD'. You can override using the `.groups` argument.

In [741]:
Eng_ttwa_nb <- df %>%
  poly2nb(., queen=T)
Error in df %>% poly2nb(., queen = T): lazy-load database '/Users/fangzeqiang/Library/R/3.6/library/spdep/R/spdep.rdb' is corrupt
Traceback:

1. df %>% poly2nb(., queen = T)

Reference

Moran's I

https://en.wikipedia.org/wiki/Moran%27s_I

GWR

  • Huang, B., Wu, B., & Barry, M. (2010). Geographically and temporally weighted regression for modeling spatio-temporal variation in house prices. International Journal of Geographical Information Science, 24(3), 383–401. doi:10.1080/13658810802672469

GWTR

  • Fotheringham, A. S., Crespo, R., & Yao, J. (2015). Geographical and Temporal Weighted Regression (GTWR). Geographical Analysis, 47(4), 431–452. doi:10.1111/gean.12071